﻿
-- =============================================
-- Author:		<Author,XFL>
-- Create date: <Create Date,2012 02 08>
-- Description:	<Description,[人资管理]-[员工工资管理]-[生成工资及核算]-[核算工资]-[团队业绩核准 查询]>
-- =============================================
CREATE PROCEDURE [dbo].[proc_Wage_TeCheng_Department_XFL]
(
	@DepartmentId int,
	@StartDate DateTime,
	@EndDate DateTime,
	@TypeId int
)	
AS
BEGIN

	SET NOCOUNT ON;

			declare @bmbh_T  varchar(50)
			set @bmbh_T = (select bmbh  FROM department WHERE id=@DepartmentId)		


select 
			ProductId,
			ProductName,
			Count(Id) As Num,
			Sum(SalePrice) As SalePrice,
			Sum(CostPrice) As CostPrice
from Project
Where TypeId=@TypeId 
			and OrderId in
			(Select distinct [Order].OId From [Order]
			where StateId In(3,4,5) And 
			ShiShouPrice >= YingShouPrice*0.5 And 
			DepId In (select Id from department where left(bmbh,len(@bmbh_T))=@bmbh_T) And 
			(TradeDate between @StartDate And @EndDate))
Group by ProductId,ProductName
END

